﻿using System;
using System.Collections.Generic;

class Workdays
{
    static void Main()
    {
        //Exercise 5.
        //Write a method that calculates the number of workdays between today and given date, passed as parameter. Consider that 
        //workdays are all days from Monday to Friday except a fixed list of public holidays specified preliminary as array.

        Console.Write("Enter a date in YYYY, MM, DD format");
        string[] endDateString = Console.ReadLine().Split(',');
        int day = int.Parse(endDateString[2]);
        int month = int.Parse(endDateString[1]);
        int year = int.Parse(endDateString[0]);
        
        DateTime startDate = DateTime.Today;
        DateTime endDate = new DateTime(year, month, day);
        int timeFrame = Math.Abs((endDate - startDate).Days);
               
        if (startDate > endDate)
        {
            startDate = endDate;
            endDate = DateTime.Today;
        }

        List<DateTime> holidays = new List<DateTime>();
        holidays.Add(new DateTime(2013, 01, 01));
        holidays.Add(new DateTime(2013, 03, 03));
        holidays.Add(new DateTime(2013, 05, 01));
        holidays.Add(new DateTime(2013, 05, 02));
        holidays.Add(new DateTime(2013, 05, 03));
        holidays.Add(new DateTime(2013, 05, 06));
        holidays.Add(new DateTime(2013, 05, 24));
        holidays.Add(new DateTime(2013, 09, 06));
        holidays.Add(new DateTime(2013, 09, 22));
        holidays.Add(new DateTime(2013, 12, 24));
        holidays.Add(new DateTime(2013, 12, 25));
        holidays.Add(new DateTime(2013, 12, 26));
        holidays.Add(new DateTime(2013, 12, 31));

        int workDayCounter = 0;
        bool isHoliday = false;

        for (int i = 0; i < timeFrame; i++)
        {
            startDate = startDate.AddDays(1);
            if (startDate.DayOfWeek != DayOfWeek.Sunday && startDate.DayOfWeek != DayOfWeek.Saturday)
            {
                for (int j = 0; j < holidays.Count; j++)
                {
                    if (startDate == holidays[j])
                    {
                        isHoliday = true;
                        break;
                    }
                }
                if (!isHoliday)
                {
                    workDayCounter++;
                }
                isHoliday = false;
            }
        }
        Console.WriteLine("The number of workdays is:  {0}", workDayCounter);

    }
}

